#ifndef __mytime__
#define __mytime__

// 从互联网同步时间到芯片
bool SetRTCTime() {
  // Variables to save date and time
  String formattedDate;
  String dayStamp;

  bool ret = timeClient.update();
  if (ret) {

#ifdef _RTC_
    // The formattedDate comes with the following format: 2018-05-28T16:00:13Z
    // We need to extract date and time
    formattedDate = timeClient.getFormattedDate();
    // Serial.println(formattedDate);
    // Extract date
    int splitT = formattedDate.indexOf("T");
    dayStamp = formattedDate.substring(0, splitT);
    rtc.set(timeClient.getSeconds(),
            timeClient.getMinutes(),
            timeClient.getHours(),
            timeClient.getDay(),
            dayStamp.substring(8, 10).toInt(),
            dayStamp.substring(5, 7).toInt(),
            dayStamp.substring(2, 4).toInt());
    //  RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
#else
    // 显示当前时间
    Serial.print("Now DateTime: ");
    Serial.print(hour);
    Serial.print("/");
    Serial.print(minu);
    Serial.print("/");
    Serial.print(seco);
    Serial.println(" // - DOW: 0 -------------------- ");

    hour = timeClient.getHours(),
    minu = timeClient.getMinutes(),
    seco = timeClient.getSeconds(),
#endif

    // 显示互联网时间
    Serial.print("NTP DateTime: ");
    Serial.print(timeClient.getFormattedTime());
    Serial.print(" ");
    Serial.print(dayStamp.substring(0, 4));
    Serial.print("/");
    Serial.print(dayStamp.substring(5, 7));
    Serial.print("/");
    Serial.print(dayStamp.substring(8, 10));
    Serial.print(" - DOW: ");
    Serial.print(timeClient.getDay());
    Serial.println(" -------------------- ");
  } else {
    Serial.println("NTP Error !!! -------------------- ");
  }
  return ret;
}

#endif